﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Utility;
using System.Data.SqlClient;

namespace HRM.DLL
{
    public class Role
    {
        public DataTable GetAllRoles()
        {
            SqlHelper objSqlHelper = new SqlHelper();
            IDataReader dr = objSqlHelper.ExecuteReader("prGetRoles");
            DataTable dt = new DataTable();
            dt.Load(dr);
            dr.Dispose();
            objSqlHelper.Dispose();
            return dt;
        }

        public DataTable GetByID(int RoleID)
        {
            SqlHelper objSqlHelper = new SqlHelper();
           
            objSqlHelper.AddParameter("@ID", RoleID);
            IDataReader dr = objSqlHelper.ExecuteReader("prRolesGetByID");
            DataTable dt = new DataTable();
            dt.Load(dr);
            dr.Dispose();
            objSqlHelper.Dispose();
            return dt;
        }

        public int Save(BO.Role objRole)
        {
            SqlHelper objSqlHelper = new SqlHelper();
            objSqlHelper.AddParameter("@ID", objRole.ID);
            objSqlHelper.AddParameter("@RoleName", objRole.RoleName);
            objSqlHelper.AddParameter("@Description", objRole.Description);
            return objSqlHelper.ExecuteNonQuery("prRolesInsertUpdate");
        }

        public int Delete(int RoleID)
        {
            SqlHelper objSqlHelper = new SqlHelper();
            objSqlHelper.AddParameter("@ID", RoleID);

            //output parameter
            SqlParameter pa = new SqlParameter();
            pa.ParameterName = "@Status";
            pa.Direction = ParameterDirection.Output;
            pa.SqlDbType = SqlDbType.Int;
            pa.SqlValue = 0;
            objSqlHelper.AddParameter(pa);

            objSqlHelper.ExecuteNonQuery("prRolesDelete");
            string IsDeleted = Convert.ToString(pa.SqlValue);

            //return the value
            return Convert.ToInt32(IsDeleted);
        }

        //not in use
        public string DeleteMultiple(string idsToDelete)
        {
            SqlHelper objSqlHelper = new SqlHelper();
            objSqlHelper.AddParameter("@ID", idsToDelete);

            //output parameter
            SqlParameter pa = new SqlParameter();
            pa.ParameterName = "@Status";
            pa.Direction = ParameterDirection.Output;
            pa.SqlDbType = SqlDbType.VarChar;
            pa.SqlValue = "0";
            objSqlHelper.AddParameter(pa);

            objSqlHelper.ExecuteNonQuery("[prRolesDeleteMultiples]");
            return Convert.ToString(pa.SqlValue);
        }
    
    }
}
